"""
设计队列的实现(在这里我们要求用之前介绍的链表形式实现)
    在队列中实现这些步骤：
        初始化创建 Node, Queue 类
        依次添加 21 35 58 13 进队列
        返回队列头部元素
        删除此时队列头部元素
        返回此时队列头部元素
"""


class Node:
    def __init__(self, data: object, node: object):
        self.data = data
        self.next = node


class Queue:
    def __init__(self, capacity: int):
        self.capacity = capacity
        self.head = Node(data=None, node=None)
        self.tail = self.head

    def enqueue(self, element: object) -> bool:
        if not self.full():
            node = Node(data=element, node=None)
            self.tail.next = node
            self.tail = node
            return True
        return False

    def dequeue(self) -> object:
        if not self.empty():
            node = self.head.next
            self.head.next = node.next
            return node.data
        return None

    def length(self) -> int:
        node = self.head
        count = 0
        while node.next != None:
            node = node.next
            count += 1
        return count

    def empty(self) -> bool:
        if self.head.next == None:
            return True
        return False

    def full(self) -> bool:
        if self.length() == self.capacity:
            return True
        return False

    def peek(self) -> object:
        return self.head.next.data

    def browse(self) -> None:
        node = self.head
        while node.next != None:
            node = node.next
            print(node.data, end=" ")


queue = Queue(5)
queue.enqueue(21)
queue.enqueue(35)
queue.enqueue(58)
queue.enqueue(13)
queue.browse()
print(queue.peek())
queue.dequeue()
print(queue.peek())
queue.browse()
